package com.changli03.buffered;

import org.junit.Test;

import java.io.*;

public class BufferedStreamTest {

    @Test
    public void test() {
        FileInputStream fis = null;
        FileOutputStream fos = null;

        BufferedOutputStream bos = null;
        BufferedInputStream bis = null;
        try {
            fis = new FileInputStream("D:\\后端\\File_ioStream\\home.jpg");
            fos = new FileOutputStream("D:\\后端\\File_ioStream\\home_copy.jpg");
            bis = new BufferedInputStream(fis);
            bos = new BufferedOutputStream(fos);

            byte[] buffer = new byte[1024];
            int len = 0;
            while ((len = bis.read(buffer)) != -1) {
                bos.write(buffer, 0, len);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            try {
               if(bos != null) bos.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            try {
                if(bis != null) bis.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }

        }


    }
    @Test
    public void test2() {

    }
}
